<script type="text/javascript">
var examTime = null;
$(function () {
	$.ajaxSetup({cache:false});
	 examTime = setInterval(function () {
		var time = $("#time").html();
		var tx = $("#txtime").html();
		time = parseInt(time) - 1;
		$("#time").html(time);
		console.log(time,tx);
		if(time == tx) {
			$("#yy1").css({'display':'','color':'red','font-size':'10px'});
			$("#yy").html("考试结束还有"+ tx +"分钟, 请注意考试时间!");
			
		}
		
		if (time == 0) {
			clearInterval(examTime);
			saveExam();//提交试卷
		}
	}, 50000);
});
function showPageDiv(btn,page){
	$(".showDiv").each(function(){
		$(this).hide();
	})
	$("#tags").find("li").each(function(){
		$(this).removeClass("active");
	})
	btn.parent().addClass("active");
	$("#tagContent"+page).show();
}

function saveExam() {
	var parm = $('#editExamForm').serialize();
	var url = create_url('myClass-saveExam');
	sys_submiting();
	$.ajax({type:'POST', url:url, data:parm,
		success: function(result) {
			sys_submiting_close();
			result = JSON.parse(result);
			if (result.result == 'success_look') {
				sys_msg('试卷提交成功,选择题得分:' + result.total);
				/* sys_load_handle('myClass-showMaterialAndExam.html?cc=${er.cc}&code=${er.clc}'); */
				sys_load_handle('myClass');
				$.fn.colorbox.close();
			}else if(result.result == 'success' ) {
				sys_msg('试卷提交成功,得分:' + result.total);
				/* sys_load_handle('myClass-showMaterialAndExam.html?cc=${er.cc}&code=${er.clc}'); */
				sys_load_handle('myClass');
				$.fn.colorbox.close();
			} else {
				sys_msg('操作失败，请再次尝试');
			}
		}
	});
}

function submitExam(){
	var type =$('#type').val();
	if(type == 3){
		$('.jd').each(function(){
			var jd =$(this).val();
			if(jd == '' || jd == null){
				$("#yy1").css({'display':'','color':'red','font-size':'10px'});
				$("#yy1").html("还有问题没答呢!");
				return;
			}else{
				if(confirm("确认提交试卷吗?")){
					clearInterval(examTime);
					saveExam();//提交试卷
				}
			}
		});
	} else{
		if(confirm("确认提交试卷吗?")){
			clearInterval(examTime);
			saveExam();//提交试卷
		}
	}
}
$('#editExamForm').find("input:checkbox, input:radio").not('input.ibtn').uniform();
</script>
<#import "/freemarker/modeltype_entity.ftl" as mte>
<#if a?? && a>
<span style="color: red;font-size: 20px;">试卷加载失败，模板题目类型的题目没有，请联系管理员！</span>
<button class="btn btn-primary" onclick="javascript: $.fn.colorbox.close();">关闭</button>
<#else>
<div class="panel panel-default">
<div id="yy" style="display: none;">离考试时间还有</div>
<div id="yy1" style="display: none;">离考试时间还有</div>
	<div class="panel-heading font-bold">${(ccr.ccn)!''}<span style="float: right;">剩余时间:&nbsp;&nbsp;<span style="font-size: 20px;color: red;" id="time" >${(ccr.examTime)!''}</span>&nbsp;(分钟)</span></div>
	<input type="hidden" value="${(ccr.time)!''}" id="txtime"/>
	<div style="width: 100%;">
		<div style="width: 40%;float: left;">
			<ul id="tags" class="nav nav-tabs tabs-vertical">
				<#assign page = (list?size / 10) />
				<#if (list?size % 10 > 0)><#assign page = page + 1 /></#if>
				<#list 1..page as pa>
					<li<#if (pa == 1)> class="active"</#if>><a href="javascript:;" onclick="showPageDiv($(this),'${pa}'); return false;">第 ${pa} 页</a></li>
				</#list>
			</ul>
		</div>
		<div style="float: right;margin-right: 15px;">
			<button class="btn btn-xs btn-primary" onclick="javascript: submitExam();">提交试卷</button>
		</div>
	</div>
<!-- 题目 -->
<div style="clear: both;">
	<form id="editExamForm">
		<div id="tagContent" class="tab-content " style="margin-top:0px;">
			<input type="hidden" name="code" value="${(er.code)!''}" />
			<#assign i = 0 />
			<#list 1..page as pa>
			<div class="tab-pane showDiv" id="tagContent${pa}" style="margin-top:0px; overflow-y:scroll; height:600px;<#if (pa == 1)>display: block;<#else>display: none;</#if>">
				<#list list as p>
				<#if ((p_index >= ((pa - 1) * 10)) && (p_index < (pa * 10)))>
				<h5 style="border-bottom:1px #ddd dashed; margin-top: 10px;">第${p_index + 1}题 (<@mte.Problemtype s=false value=(p.type) />${p.points}分) &nbsp;&nbsp;${p.content}</h5>
				<input type="hidden" name="trList[${i}].tc" value="${p.code}" />
				<input type="hidden" name="trList[${i}].type" value="${p.type}" />
				<input type="hidden" name="trList[${i}].points" value="${p.points}" />
				<#if (p.type == 1)>
				<#list p.tkList as pa>
					<input type="radio" name="trList[${i}].arList[0].answerCode" value="${pa.code}"/>
					${pa.answer}<br>
				</#list>
				<#elseif (p.type == 2)>
				<#assign j = 0 />
				<#list p.tkList as pa>
					<input type="checkbox" name="trList[${i}].arList[${j}].answerCode" value="${pa.code}" />
					${pa.answer}<br>
				<#assign j = j + 1 />
				</#list>
				<#elseif (p.type == 3)>
				<input id="type" value="${p.type}" type="hidden"/>
				<textarea class="form-control jd" placeholder="填写你的答案:" style="width:600px; height:100px; margin-bottom:20px;" name="trList[${i}].arList[0].content"></textarea>
				</#if>
				</#if>
				<#assign i = i + 1 />
				</#list>
			</div>
			</#list>
		</div>
	</form>
</div>
<span style="color: red;">答题时请勿刷新、关闭浏览器,答题结束请点击提交试卷,否则答题无效</span>
</div>
</#if>